package com.instasale.converters;

import com.instasale.models.Feature;
import com.instasale.services.FeatureService;
import org.springframework.core.convert.converter.Converter;

import java.util.Set;

public class StringsToFeaturesSetConverter implements Converter<String[], Set<Feature>> {

    FeatureService featureService;

    public StringsToFeaturesSetConverter(FeatureService featureService) {
        this.featureService = featureService;
    }

    @Override
    public Set<Feature> convert(String[] strings) {
        Integer[] ids = new Integer[strings.length];
        for (int i = 0; i < strings.length; i++)
            ids[i] = Integer.parseInt(strings[i]);
        return featureService.getByIds(ids);
    }
}
